<template>
  <div id="push">
   
    <!--添加规格-->
    <el-form ref="form" :model="form" label-width="80px">
      <el-form-item label="商品ID">
        <el-input v-model="form.proId"></el-input>
      </el-form-item>
      <el-form-item label="尺寸" prop="size">
        <el-radio v-model="form.size" label="13寸">13寸</el-radio>
        <el-radio v-model="form.size" label="14寸">14寸</el-radio>
        <el-radio v-model="form.size" label="15寸">15寸</el-radio>
      </el-form-item>
      <el-form-item label="颜色" prop="color">
        <el-radio v-model="form.color" label="白色">白色</el-radio>
        <el-radio v-model="form.color" label="红色">红色</el-radio>
        <el-radio v-model="form.color" label="黑色">黑色</el-radio>
      </el-form-item>
      <el-form-item label="品牌" prop="brand">
        <el-radio v-model="form.brand" label="联想">联想</el-radio>
        <el-radio v-model="form.brand" label="华为">华为</el-radio>
        <el-radio v-model="form.brand" label="苹果">苹果</el-radio>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">立即创建</el-button>
        <el-button>取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
export default {
  data() {
    return {
      form: {
        proId: this.$route.params.id,
        speAttribute: "",
        size: "",
        color: "",
        brand: "",
      },
    };
  },

  methods: {


    //添加
    onSubmit(form) {
      console.log("submit!");
      this.axios({
        url: "http://localhost:35043/api/Sepcification/AddSpec",
        method: "post",
        data: {
          size:this.form.size,
          color:this.form.color,
          brand:this.form.brand,
          speAttribute:
            "{" +
            "尺寸" +
            this.form.speAttribute +
            "," +
            "颜色" +
            this.form.speA1 +
            "," +
            "品牌" +
            this.form.speA2 +
            "}",
          proId: this.form.proId,
        },
      }).then((res) => {
        if (res.data.code == 0) {
          alert("添加成功");
          this.$router.push("/Product");
        } else {
          alert("添加失败");
          return;
        }
      });
    },
  },
};
</script>